//
//  TabBarViewController.swift
//  Swift-WB
//
//  Created by 李西亚 on 2017/5/20.
//  Copyright © 2017年 lixiya. All rights reserved.
//

import UIKit


class TabBarViewController: UITabBarController {
  
    override func viewDidLoad() {
        super.viewDidLoad()
        setUpChildViewControllers()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    func setUpChildViewControllers()  {
        let one = WBOneViewController()
        let two = WBTwoViewController()
        let three = WBThreeViewController()
        
        addChildVc(childVc: one, title: "第一页", imageName: "tabbar_nor", selectedImageName: "tabbar_sel")
        addChildVc(childVc: two, title: "第二页", imageName: "tabbar_nor", selectedImageName: "tabbar_sel")
        addChildVc(childVc: three, title: "第三页", imageName: "tabbar_nor", selectedImageName: "tabbar_sel")
    }
    
    //MARK:添加一个子控制器到UITabBarController中
    func addChildVc(childVc : UIViewController, title : String, imageName : String, selectedImageName : String) {
        childVc.tabBarItem.title = title
        
        // 设置tabBarItem上默认的指示图片和选中时的图片
        let normalImg = UIImage(named: imageName)
        let selectImg = UIImage(named: selectedImageName)
        
        childVc.tabBarItem.image = normalImg?.withRenderingMode(.alwaysOriginal)
        childVc.tabBarItem.selectedImage = selectImg?.withRenderingMode(.alwaysOriginal)
        
        childVc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .selected)
        
        let nav = NavigationController(rootViewController: childVc)
        self.addChildViewController(nav)
    }

}
